// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        prefabLeven: cc.Prefab,
        objPanel:cc.Node,
    },



    // onLoad () {},

    start() {

    },
    onJsonBtnClick(event) {
        let btnName = event.target.name;
        switch (btnName) {
            case "btn_xg":
                cc.log("加载选关界面");
                event.interactable = false;
                this.loadLevenToScene();
                break;
            default:
                cc.log("无对应按钮");
                break;
        }
    },

    loadLevenToScene() {
        var levelDatas = window.getGameLevelDataConfig(36);
        //大关数组
        var groupAreaDatas = [];
        var objLeven = cc.instantiate(this.prefabLeven);
        objLeven.name="objLevel";
        var objLevenCom = objLeven.getComponent("LevelScene");
            objLevenCom.createLevelLayer(groupAreaDatas);
        this.node.addChild(objLeven);

        for (let index = 0; index < levelDatas.length; index++) {
            //如果满了一大关创建
            if (groupAreaDatas.length === 6) {

                objLevenCom = objLeven.getComponent("LevelScene");
                objLevenCom.createLevelLayer(groupAreaDatas);
                groupAreaDatas=[];
            }
            groupAreaDatas.push(levelDatas[i]);
            cc.log("groupAreaDatas:"+groupAreaDatas);
        }
    },

    popShow(objNode) {
        objNode.scale = 0.1;
        var scaleTo = cc.scaleTo(0.3, 1.0);
        var easeOut = scaleTo.easing(cc.easeBackOut());
        objNode.active = true;
        objNode.runAction(cc.sequence(easeOut, cc.callFunc(function () {
            cc.log("动作完成");
        })));
    }

});